using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
using System.Web;
using System.Threading;

namespace Data
{
	/// <summary>
	/// Strongly-typed collection for the user class.
	/// </summary>
	[Serializable]
	public partial class userCollection : ActiveList<user, userCollection> 
	{	   
		public userCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the user table.
	/// </summary>
	[Serializable]
	public partial class user : ActiveRecord<user>
	{
		#region .ctors and Default Settings
		
		public user()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public user(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public user(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public user(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("user", TableType.Table, DataService.GetInstance("MyProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"";
				//columns
				
				TableSchema.TableColumn colvarUserID = new TableSchema.TableColumn(schema);
				colvarUserID.ColumnName = "UserID";
				colvarUserID.DataType = DbType.String;
				colvarUserID.MaxLength = 40;
				colvarUserID.AutoIncrement = false;
				colvarUserID.IsNullable = false;
				colvarUserID.IsPrimaryKey = true;
				colvarUserID.IsForeignKey = false;
				colvarUserID.IsReadOnly = false;
				colvarUserID.DefaultSetting = @"";
				colvarUserID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserID);
				
				TableSchema.TableColumn colvarUserName = new TableSchema.TableColumn(schema);
				colvarUserName.ColumnName = "UserName";
				colvarUserName.DataType = DbType.String;
				colvarUserName.MaxLength = 50;
				colvarUserName.AutoIncrement = false;
				colvarUserName.IsNullable = false;
				colvarUserName.IsPrimaryKey = false;
				colvarUserName.IsForeignKey = false;
				colvarUserName.IsReadOnly = false;
				colvarUserName.DefaultSetting = @"";
				colvarUserName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserName);
				
				TableSchema.TableColumn colvarPassword = new TableSchema.TableColumn(schema);
				colvarPassword.ColumnName = "Password";
				colvarPassword.DataType = DbType.String;
				colvarPassword.MaxLength = 50;
				colvarPassword.AutoIncrement = false;
				colvarPassword.IsNullable = false;
				colvarPassword.IsPrimaryKey = false;
				colvarPassword.IsForeignKey = false;
				colvarPassword.IsReadOnly = false;
				colvarPassword.DefaultSetting = @"";
				colvarPassword.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPassword);
				
				TableSchema.TableColumn colvarEmail = new TableSchema.TableColumn(schema);
				colvarEmail.ColumnName = "Email";
				colvarEmail.DataType = DbType.String;
				colvarEmail.MaxLength = 125;
				colvarEmail.AutoIncrement = false;
				colvarEmail.IsNullable = false;
				colvarEmail.IsPrimaryKey = false;
				colvarEmail.IsForeignKey = false;
				colvarEmail.IsReadOnly = false;
				colvarEmail.DefaultSetting = @"";
				colvarEmail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEmail);
				
				TableSchema.TableColumn colvarAddress = new TableSchema.TableColumn(schema);
				colvarAddress.ColumnName = "Address";
				colvarAddress.DataType = DbType.String;
				colvarAddress.MaxLength = 255;
				colvarAddress.AutoIncrement = false;
				colvarAddress.IsNullable = true;
				colvarAddress.IsPrimaryKey = false;
				colvarAddress.IsForeignKey = false;
				colvarAddress.IsReadOnly = false;
				colvarAddress.DefaultSetting = @"";
				colvarAddress.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAddress);
				
				TableSchema.TableColumn colvarPhone = new TableSchema.TableColumn(schema);
				colvarPhone.ColumnName = "Phone";
				colvarPhone.DataType = DbType.String;
				colvarPhone.MaxLength = 20;
				colvarPhone.AutoIncrement = false;
				colvarPhone.IsNullable = true;
				colvarPhone.IsPrimaryKey = false;
				colvarPhone.IsForeignKey = false;
				colvarPhone.IsReadOnly = false;
				colvarPhone.DefaultSetting = @"";
				colvarPhone.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPhone);
				
				TableSchema.TableColumn colvarDOB = new TableSchema.TableColumn(schema);
				colvarDOB.ColumnName = "DOB";
				colvarDOB.DataType = DbType.String;
				colvarDOB.MaxLength = 10;
				colvarDOB.AutoIncrement = false;
				colvarDOB.IsNullable = true;
				colvarDOB.IsPrimaryKey = false;
				colvarDOB.IsForeignKey = false;
				colvarDOB.IsReadOnly = false;
				colvarDOB.DefaultSetting = @"";
				colvarDOB.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDOB);
				
				TableSchema.TableColumn colvarDescription = new TableSchema.TableColumn(schema);
				colvarDescription.ColumnName = "Description";
				colvarDescription.DataType = DbType.String;
				colvarDescription.MaxLength = 500;
				colvarDescription.AutoIncrement = false;
				colvarDescription.IsNullable = true;
				colvarDescription.IsPrimaryKey = false;
				colvarDescription.IsForeignKey = false;
				colvarDescription.IsReadOnly = false;
				colvarDescription.DefaultSetting = @"";
				colvarDescription.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDescription);
				
				TableSchema.TableColumn colvarActive = new TableSchema.TableColumn(schema);
				colvarActive.ColumnName = "Active";
				colvarActive.DataType = DbType.Boolean;
				colvarActive.MaxLength = 1;
				colvarActive.AutoIncrement = false;
				colvarActive.IsNullable = false;
				colvarActive.IsPrimaryKey = false;
				colvarActive.IsForeignKey = false;
				colvarActive.IsReadOnly = false;
				colvarActive.DefaultSetting = @"";
				colvarActive.ForeignKeyTableName = "";
				schema.Columns.Add(colvarActive);
				
				TableSchema.TableColumn colvarUserType = new TableSchema.TableColumn(schema);
				colvarUserType.ColumnName = "UserType";
				colvarUserType.DataType = DbType.Int32;
				colvarUserType.MaxLength = 11;
				colvarUserType.AutoIncrement = false;
				colvarUserType.IsNullable = true;
				colvarUserType.IsPrimaryKey = false;
				colvarUserType.IsForeignKey = false;
				colvarUserType.IsReadOnly = false;
				colvarUserType.DefaultSetting = @"";
				colvarUserType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserType);
				
				TableSchema.TableColumn colvarCreatedDate = new TableSchema.TableColumn(schema);
				colvarCreatedDate.ColumnName = "CreatedDate";
				colvarCreatedDate.DataType = DbType.DateTime;
				colvarCreatedDate.MaxLength = 0;
				colvarCreatedDate.AutoIncrement = false;
				colvarCreatedDate.IsNullable = true;
				colvarCreatedDate.IsPrimaryKey = false;
				colvarCreatedDate.IsForeignKey = false;
				colvarCreatedDate.IsReadOnly = false;
				colvarCreatedDate.DefaultSetting = @"";
				colvarCreatedDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedDate);
				
				TableSchema.TableColumn colvarUpdateDate = new TableSchema.TableColumn(schema);
				colvarUpdateDate.ColumnName = "UpdateDate";
				colvarUpdateDate.DataType = DbType.DateTime;
				colvarUpdateDate.MaxLength = 0;
				colvarUpdateDate.AutoIncrement = false;
				colvarUpdateDate.IsNullable = true;
				colvarUpdateDate.IsPrimaryKey = false;
				colvarUpdateDate.IsForeignKey = false;
				colvarUpdateDate.IsReadOnly = false;
				colvarUpdateDate.DefaultSetting = @"";
				colvarUpdateDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUpdateDate);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MyProvider"].AddSchema("user",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("UserID")]
		public string UserID 
		{
			get { return GetColumnValue<string>("UserID"); }

			set { SetColumnValue("UserID", value); }

		}

		  
		[XmlAttribute("UserName")]
		public string UserName 
		{
			get { return GetColumnValue<string>("UserName"); }

			set { SetColumnValue("UserName", value); }

		}

		  
		[XmlAttribute("Password")]
		public string Password 
		{
			get { return GetColumnValue<string>("Password"); }

			set { SetColumnValue("Password", value); }

		}

		  
		[XmlAttribute("Email")]
		public string Email 
		{
			get { return GetColumnValue<string>("Email"); }

			set { SetColumnValue("Email", value); }

		}

		  
		[XmlAttribute("Address")]
		public string Address 
		{
			get { return GetColumnValue<string>("Address"); }

			set { SetColumnValue("Address", value); }

		}

		  
		[XmlAttribute("Phone")]
		public string Phone 
		{
			get { return GetColumnValue<string>("Phone"); }

			set { SetColumnValue("Phone", value); }

		}

		  
		[XmlAttribute("DOB")]
		public string DOB 
		{
			get { return GetColumnValue<string>("DOB"); }

			set { SetColumnValue("DOB", value); }

		}

		  
		[XmlAttribute("Description")]
		public string Description 
		{
			get { return GetColumnValue<string>("Description"); }

			set { SetColumnValue("Description", value); }

		}

		  
		[XmlAttribute("Active")]
		public bool Active 
		{
			get { return GetColumnValue<bool>("Active"); }

			set { SetColumnValue("Active", value); }

		}

		  
		[XmlAttribute("UserType")]
		public int? UserType 
		{
			get { return GetColumnValue<int?>("UserType"); }

			set { SetColumnValue("UserType", value); }

		}

		  
		[XmlAttribute("CreatedDate")]
		public DateTime? CreatedDate 
		{
			get { return GetColumnValue<DateTime?>("CreatedDate"); }

			set { SetColumnValue("CreatedDate", value); }

		}

		  
		[XmlAttribute("UpdateDate")]
		public DateTime? UpdateDate 
		{
			get { return GetColumnValue<DateTime?>("UpdateDate"); }

			set { SetColumnValue("UpdateDate", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varUserID,string varUserName,string varPassword,string varEmail,string varAddress,string varPhone,string varDOB,string varDescription,bool varActive,int? varUserType,DateTime? varCreatedDate,DateTime? varUpdateDate)
		{
			user item = new user();
			
			item.UserID = varUserID;
			
			item.UserName = varUserName;
			
			item.Password = varPassword;
			
			item.Email = varEmail;
			
			item.Address = varAddress;
			
			item.Phone = varPhone;
			
			item.DOB = varDOB;
			
			item.Description = varDescription;
			
			item.Active = varActive;
			
			item.UserType = varUserType;
			
			item.CreatedDate = varCreatedDate;
			
			item.UpdateDate = varUpdateDate;
			
		
			if (HttpContext.Current != null)
				item.Save(HttpContext.Current.User.Identity.Name);
			else
				item.Save(Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varUserID,string varUserName,string varPassword,string varEmail,string varAddress,string varPhone,string varDOB,string varDescription,bool varActive,int? varUserType,DateTime? varCreatedDate,DateTime? varUpdateDate)
		{
			user item = new user();
			
				item.UserID = varUserID;
				
				item.UserName = varUserName;
				
				item.Password = varPassword;
				
				item.Email = varEmail;
				
				item.Address = varAddress;
				
				item.Phone = varPhone;
				
				item.DOB = varDOB;
				
				item.Description = varDescription;
				
				item.Active = varActive;
				
				item.UserType = varUserType;
				
				item.CreatedDate = varCreatedDate;
				
				item.UpdateDate = varUpdateDate;
				
			item.IsNew = false;
			if (HttpContext.Current != null)
				item.Save(HttpContext.Current.User.Identity.Name);
			else
				item.Save(Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			int i;
			 public static string UserID = @"UserID";
			 public static string UserName = @"UserName";
			 public static string Password = @"Password";
			 public static string Email = @"Email";
			 public static string Address = @"Address";
			 public static string Phone = @"Phone";
			 public static string DOB = @"DOB";
			 public static string Description = @"Description";
			 public static string Active = @"Active";
			 public static string UserType = @"UserType";
			 public static string CreatedDate = @"CreatedDate";
			 public static string UpdateDate = @"UpdateDate";
						
		}

		#endregion
	}

}

